﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace MyGames
{
    class Particle : GameObject
    {
        static ContentManager content = GameLoader.Content;
        static string[] attackTypePath = { "Claw", "Slash", "Arrow", "Magic" };

        #region Properties
        public bool IsFinished
        {
            get { return !enabled; }
        }
        #endregion

        #region Constructor
        public Particle(AttackType type, Character reciever, bool crit)
        {
            string path = Const.TexturePathParticle;
            int r = 1, c = 1;
            if (!crit) path += attackTypePath[(int)type] + "0";//RandomHelper.rand.Next(2);
            else { path += "Crit"; c = 5; r = 1; }

            animations.Add("particle", new AnimationStrip(content.Load<Texture2D>(path), r, c, "particle"));
            animations["particle"].FrameLength = (crit ? 0.05f : 0.15f);
            PlayAnimation("particle");

            worldLocation = reciever.WorldCenter;
            scale = reciever.FrameHeight * 1f / FrameHeight + 0.4f;

            enabled = true;
        }
        #endregion

        #region Update and Draw
        public override void Update(GameTime gameTime)
        {
            if (animations[currentAnimation].FinishedPlaying && enabled)
                enabled = false;
            base.Update(gameTime);
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            if (!enabled)
                return;
            if (animations.ContainsKey(currentAnimation))
            {
                Vector2 og = new Vector2(animations[currentAnimation].FrameWidth / 2, animations[currentAnimation].FrameHeight / 2);
                spriteBatch.Draw(
                    animations[currentAnimation].Texture,
                    Camera.WorldToScreen(WorldLocation),
                    animations[currentAnimation].FrameRectangle,
                    affectColor, 0f, og, scale, SpriteEffects.None, drawDepth);
            }
        }

        protected override Point offset()
        {
            return new Point(animations[currentAnimation].FrameWidth / 2, animations[currentAnimation].FrameHeight / 2);
        }
        #endregion
    }
}
